//登录拦截
import router from '../router'
import Vue from 'vue'
import managerApi from '../api/managerApi'

//拦截 路由跳转前拦截
router.beforeEach((to,from,next)=>{
	let url =to.path;
	if(url == '/manager/login'){
		next();
	}else{
		let token = Vue.cookie.get("token-survey1905");
		if(token){
			managerApi.checkToken(token)
			.then(({data})=>{
				if(data.data){
					next();//放行
				}else{
					Vue.cookie.delete("token-survey1905")
					router.push({
						path:'/manager/login'
					})
				}
			})
		}else{
			router.push({
				path:'/manager/login'
			})
		}
	}
})